package com.uyaer.engine.res
{
	/**
	 *保存下载数据 
	 * @author hc
	 * 
	 */	
	public class Receiver
	{
		/**
		 *资源
		 */		
		private var res:Array = new Array();
		/**
		 *权重 
		 */		
		public var order:int = 0;
		/**
		 *成功回调 
		 */		
		public var overCallback:Function;
		/**
		 *进度回调 
		 */		
		public var progressCallback:Function;
		/**
		 *错误回调 
		 */		
		public var errorCallback:Function;
		
		private var _isGroup:Boolean;
		/**
		 *每一百分比 
		 */		
		private var _per:Number;
		/**
		 *总体百分比 
		 */		
		private var _perAll:Number;
		
		public function Receiver(urls:* ,overCallback:Function = null,progressCallback:Function = null,
								 errorCallback:Function = null, order:int = 0){
			if(urls is String){
				res.push(urls);
			}else if(urls is Array){
				res = urls;
				if(res.length>1){
					_isGroup = true;
				}
			}
			_per = 1 / res.length;
			this.overCallback = overCallback;
			this.progressCallback = progressCallback;
			this.errorCallback = errorCallback;
			this.order = order;
		}
		
		/**
		 *是否有下一条 
		 * @return 
		 * 
		 */		
		public function hasNext():Boolean{
			return res.length != 0;
		}
		
		/**
		 *获取下一条 
		 * @return 
		 * 
		 */		
		public function next():String{
			if(res.length>0){
				_perAll = _per * (res.length - 1);
			}else{
				_perAll = 0;
			}
			return res.pop();
		}
		
		/**
		 *是否是成组的接收器
		 * @return 
		 * 
		 */		
		public function get isGroup():Boolean{
			return _isGroup;
		}
		
		/**
		 * 每一百分比
		 * @return 
		 */		
		public function get per():Number{
			return _per;
		}
		
		/**
		 * 总体百分比
		 * @return 
		 */		
		public function get perAll():Number{
			return _perAll;
		}
	}
}